/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * WizardVerifierLib.java
 *
 * Created on Jun 9, 2010, 9:57:36 AM
 */
package UserInterface;

import env.ComparisonSettings;
import java.awt.Toolkit;
import java.beans.PropertyChangeSupport;
import java.io.File;

/**
 *
 * @author Kyle
 */
public class WizardVerifierLib extends javax.swing.JFrame
{
    boolean editing = false;
    int editIndex = 0;
    int lines = 0;
    String conceptLib;
    protected PropertyChangeSupport propertyChange = new PropertyChangeSupport(this);
    private int screen = 0;
    private ComparisonSettings compare;
    private java.awt.Frame FATHER_WINDOW_HANDLE;
    private final String msg = "You are currently managing your Verifier dictionary settings.  " +
            "Verifier dictionaries should have one entry per line. " +
            "Each of these words will be searched for inside and/or around each annotation.  " +
            "A text file explaining the rules for this dictionary may also be linked with the dictionary to provide the user with a reference point for making annotation decisions.  " +
            "If you want the entry to be compared character by character tag it with <char> before the entry.";

    /** Creates new form WizardVerifierLib */
    public WizardVerifierLib(java.awt.Frame _FATHER_WINDOW_HANDLE)
    {
        compare = env.Parameters.verifierComparisonSettings;
        screen = 1;

        initComponents();

        FATHER_WINDOW_HANDLE = _FATHER_WINDOW_HANDLE;

        jTextArea1.setText(msg);        
        jButton_back.setEnabled(false);
        jPanel_CardLayout.removeAll();
        jPanel_CardLayout.add(jPanel_Introduction, "1");
        jPanel_CardLayout.repaint();
    }
    /**
     * The constructor to edit a Verifier Dictionary
     * @param _FATHER_WINDOW_HANDLE - The Father frame
     * @param toEdit - The dictionary we're editing
     * @param index - The index of the dictionary we're editing
     */
    public WizardVerifierLib(java.awt.Frame _FATHER_WINDOW_HANDLE, Dictionaries.VerifierDictionaryFormat toEdit, int index)
    {
        //Set editing to true, and set the screen to 4
        editing = true;
        editIndex = index;
        screen = 4;
        lines = env.Parameters.VERIFIER_DICTIONARIES.get(index).getNumberOfEntries();

        //Initialize components
        initComponents();

        //Get GUI ready.
        jButton_next.setText("SaveChanges");
        jButton_back.setEnabled(false);

        //Extract info from this dictionary so we can edit it.
        conceptLib = toEdit.getFileName();
        boolean checkAround = toEdit.isCheckAround();
        int before = toEdit.getWordsBefore();
        int after = toEdit.getWordsAfter();
        int charsAfter = toEdit.getCharByCharAfter();
        boolean inside = toEdit.isCheckInside();
        jCheckBox1.setSelected(checkAround);
        checkInside.setSelected(inside);
        jComboBox1.setSelectedIndex(before);
        jComboBox2.setSelectedIndex(after);
        charByChar.setSelectedIndex(charsAfter);
        this.checkFirst.setSelected(toEdit.isFirstOnly());
        this.checkLast.setSelected(toEdit.isLastOnly());
        jTextField1.setText(toEdit.getExplanationFileNameAbsolute());

        //Store the father window.
        FATHER_WINDOW_HANDLE = _FATHER_WINDOW_HANDLE;

        //Set up GUI for editing
        jTextArea1.setText(msg);
        jButton_back.setEnabled(false);
        jPanel_CardLayout.removeAll();
        jPanel_CardLayout.add(jPanelOptions, "4");
        jPanel_CardLayout.repaint();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jFileChooser1 = new javax.swing.JFileChooser();
        jButton_cancel = new javax.swing.JButton();
        jButton_next = new javax.swing.JButton();
        jButton_back = new javax.swing.JButton();
        jPanel_CardLayout = new javax.swing.JPanel();
        jPanel_Introduction = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jPanel_choosefile = new javax.swing.JPanel();
        jTextField_ConceptLib = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jPanel_Done = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jPanelOptions = new javax.swing.JPanel();
        jCheckBox1 = new javax.swing.JCheckBox();
        jLabel23 = new javax.swing.JLabel();
        checkInside = new javax.swing.JCheckBox();
        jComboBox1 = new javax.swing.JComboBox();
        jComboBox2 = new javax.swing.JComboBox();
        jTextField1 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jLabel24 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jLabel25 = new javax.swing.JLabel();
        checkFirst = new javax.swing.JCheckBox();
        checkLast = new javax.swing.JCheckBox();
        jLabel26 = new javax.swing.JLabel();
        jLabel27 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jComboBox3 = new javax.swing.JComboBox();
        jLabel15 = new javax.swing.JLabel();
        charByChar = new javax.swing.JComboBox();

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jButton_cancel.setText("Cancel");
        jButton_cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_cancelActionPerformed(evt);
            }
        });
        getContentPane().add(jButton_cancel, new org.netbeans.lib.awtextra.AbsoluteConstraints(500, 320, -1, -1));

        jButton_next.setText("Next");
        jButton_next.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_nextActionPerformed(evt);
            }
        });
        getContentPane().add(jButton_next, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 320, -1, -1));

        jButton_back.setText("Back");
        jButton_back.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_backActionPerformed(evt);
            }
        });
        getContentPane().add(jButton_back, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 320, -1, -1));

        jPanel_CardLayout.setMaximumSize(new java.awt.Dimension(558, 305));
        jPanel_CardLayout.setLayout(new java.awt.CardLayout());

        jPanel_Introduction.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jPanel_Introduction.setFont(new java.awt.Font("Segoe UI Light", 1, 14));
        jPanel_Introduction.setMaximumSize(new java.awt.Dimension(558, 305));
        jPanel_Introduction.setRequestFocusEnabled(false);
        jPanel_Introduction.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/3.png"))); // NOI18N
        jPanel_Introduction.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(24, 46, -1, -1));

        jLabel2.setFont(new java.awt.Font("Segoe UI", 1, 14));
        jLabel2.setText("Introduction");
        jPanel_Introduction.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(179, 21, -1, -1));

        jTextArea1.setBackground(new java.awt.Color(244, 244, 244));
        jTextArea1.setColumns(20);
        jTextArea1.setFont(new java.awt.Font("Segoe UI", 0, 12));
        jTextArea1.setLineWrap(true);
        jTextArea1.setRows(5);
        jTextArea1.setWrapStyleWord(true);
        jTextArea1.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        jTextArea1.setEnabled(false);
        jTextArea1.setFocusable(false);
        jScrollPane1.setViewportView(jTextArea1);

        jPanel_Introduction.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(179, 46, 416, 238));

        jPanel_CardLayout.add(jPanel_Introduction, "card2");

        jPanel_choosefile.setMaximumSize(new java.awt.Dimension(558, 305));
        jPanel_choosefile.setPreferredSize(new java.awt.Dimension(558, 305));
        jPanel_choosefile.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jTextField_ConceptLib.setText("jTextField1");
        jPanel_choosefile.add(jTextField_ConceptLib, new org.netbeans.lib.awtextra.AbsoluteConstraints(24, 121, 319, -1));

        jLabel3.setFont(new java.awt.Font("Segoe UI", 1, 14));
        jLabel3.setText("Make a change");
        jPanel_choosefile.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(24, 20, -1, -1));

        jLabel17.setFont(new java.awt.Font("Segoe UI", 0, 12));
        jLabel17.setText("Choose the source file for your Dictionary. ");
        jPanel_choosefile.add(jLabel17, new org.netbeans.lib.awtextra.AbsoluteConstraints(24, 45, -1, -1));
        jPanel_choosefile.add(jLabel19, new org.netbeans.lib.awtextra.AbsoluteConstraints(462, 95, -1, 149));

        jLabel20.setText("Verifier Dictionary");
        jPanel_choosefile.add(jLabel20, new org.netbeans.lib.awtextra.AbsoluteConstraints(24, 97, -1, -1));

        jLabel21.setFont(new java.awt.Font("Segoe UI", 0, 12));
        jLabel21.setForeground(new java.awt.Color(204, 0, 0));
        jLabel21.setText("jLabel21");
        jPanel_choosefile.add(jLabel21, new org.netbeans.lib.awtextra.AbsoluteConstraints(24, 264, -1, -1));

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/change24.png"))); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel_choosefile.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 116, 27, 33));

        jPanel_CardLayout.add(jPanel_choosefile, "card3");

        jPanel_Done.setMaximumSize(new java.awt.Dimension(558, 305));
        jPanel_Done.setPreferredSize(new java.awt.Dimension(558, 305));
        jPanel_Done.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel4.setFont(new java.awt.Font("Segoe UI", 0, 12));
        jLabel4.setText("System will automatically check dictionary validity.");
        jPanel_Done.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(36, 45, -1, -1));

        jLabel5.setFont(new java.awt.Font("Segoe UI", 0, 12));
        jLabel5.setText("System checking ...");
        jPanel_Done.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(36, 101, -1, -1));

        jLabel7.setFont(new java.awt.Font("Segoe UI", 0, 12));
        jLabel7.setForeground(new java.awt.Color(0, 0, 153));
        jLabel7.setText("jLabel7");
        jPanel_Done.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 134, 362, -1));

        jLabel8.setFont(new java.awt.Font("Segoe UI", 0, 12));
        jLabel8.setForeground(new java.awt.Color(0, 0, 153));
        jLabel8.setText("jLabel8");
        jPanel_Done.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 157, 362, -1));

        jLabel9.setFont(new java.awt.Font("Segoe UI", 0, 12));
        jLabel9.setForeground(new java.awt.Color(0, 0, 153));
        jLabel9.setText("jLabel9");
        jPanel_Done.add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 180, 362, -1));
        jPanel_Done.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(34, 134, -1, -1));
        jPanel_Done.add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(34, 157, -1, -1));

        jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/mark1.png"))); // NOI18N
        jPanel_Done.add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(23, 180, -1, -1));

        jLabel13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/BackUp.png"))); // NOI18N
        jPanel_Done.add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(420, 101, -1, -1));

        jLabel14.setFont(new java.awt.Font("Segoe UI", 1, 14));
        jLabel14.setText("Evaluate changes and Save it");
        jPanel_Done.add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(36, 20, -1, -1));

        jLabel16.setFont(new java.awt.Font("Segoe UI", 1, 12));
        jLabel16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/markerror.png"))); // NOI18N
        jLabel16.setText("jLabel16");
        jPanel_Done.add(jLabel16, new org.netbeans.lib.awtextra.AbsoluteConstraints(23, 268, -1, -1));

        jPanel_CardLayout.add(jPanel_Done, "card4");

        jCheckBox1.setText("Check Around Span");
        jCheckBox1.setToolTipText("<html>Mark this if you want to check around the annotation<br> for words from this dictionary.</html>");

        jLabel23.setText("Words After:");

        checkInside.setText("Check Inside Span");
        checkInside.setToolTipText("<html>Mark this if you want to check inside of the<br> annotation for words from this dictionary.</html>");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }));
        jComboBox1.setSelectedIndex(4);
        jComboBox1.setToolTipText("<html> The number of words before the annotation that should<br> be checked for words from this dictionary.</html>");

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }));
        jComboBox2.setSelectedIndex(4);
        jComboBox2.setToolTipText("<html> The number of words after the annotation that should<br> be checked for words from this dictionary.</html>");

        jTextField1.setToolTipText("The text file containing the rules for this dictionary.");

        jLabel6.setLabelFor(jTextField1);
        jLabel6.setText("Linked Explanation Text File(optional):");

        jButton2.setText("Browse...");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Check Explanation File");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel25.setFont(new java.awt.Font("Segoe UI", 1, 14));
        jLabel25.setText("Annotation Search Settings");

        checkFirst.setText("Only Check First");
        checkFirst.setToolTipText("Only check the first word in the annotation.");

        checkLast.setText("Only Check Last");
        checkLast.setToolTipText("Only check the last word in the annotation.");

        jLabel26.setText("Number of Entries Allowed:");

        jLabel27.setText("(By default all words in the annotation will be checked)");

        jLabel22.setText("Words Before:");

        jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }));
        jComboBox3.setToolTipText("<html>The number of words from this dictionary that can be<br> found in an annotation before it is flagged.</html>");

        jLabel15.setText("Characters After:");

        charByChar.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }));
        charByChar.setToolTipText("<html> The number of characters after the annotation that should<br> be checked for words from this dictionary.<br>Only entries preceded by a <char> tag will be used for this check.</html>");

        javax.swing.GroupLayout jPanelOptionsLayout = new javax.swing.GroupLayout(jPanelOptions);
        jPanelOptions.setLayout(jPanelOptionsLayout);
        jPanelOptionsLayout.setHorizontalGroup(
            jPanelOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelOptionsLayout.createSequentialGroup()
                .addGroup(jPanelOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelOptionsLayout.createSequentialGroup()
                        .addGap(111, 111, 111)
                        .addComponent(jLabel27))
                    .addGroup(jPanelOptionsLayout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 270, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jButton2))
                    .addGroup(jPanelOptionsLayout.createSequentialGroup()
                        .addGap(180, 180, 180)
                        .addComponent(jButton3)
                        .addGap(39, 39, 39)
                        .addComponent(jLabel24, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelOptionsLayout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(jLabel25, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelOptionsLayout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addComponent(jCheckBox1))
                    .addGroup(jPanelOptionsLayout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addGroup(jPanelOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(checkInside)
                            .addGroup(jPanelOptionsLayout.createSequentialGroup()
                                .addGap(47, 47, 47)
                                .addGroup(jPanelOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(jPanelOptionsLayout.createSequentialGroup()
                                        .addComponent(jLabel22)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                                    .addComponent(checkFirst))
                                .addGroup(jPanelOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanelOptionsLayout.createSequentialGroup()
                                        .addGap(30, 30, 30)
                                        .addComponent(checkLast)
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabel26)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanelOptionsLayout.createSequentialGroup()
                                        .addGap(42, 42, 42)
                                        .addComponent(jLabel23)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(44, 44, 44)
                                        .addComponent(jLabel15)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(charByChar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))))
                .addContainerGap(41, Short.MAX_VALUE))
        );
        jPanelOptionsLayout.setVerticalGroup(
            jPanelOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelOptionsLayout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jLabel25)
                .addGap(30, 30, 30)
                .addComponent(jCheckBox1)
                .addGap(17, 17, 17)
                .addGroup(jPanelOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel22)
                    .addComponent(charByChar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel23)
                    .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(6, 6, 6)
                .addComponent(checkInside)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(checkFirst)
                    .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel26, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(checkLast))
                .addGap(4, 4, 4)
                .addComponent(jLabel27)
                .addGap(36, 36, 36)
                .addGroup(jPanelOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel6))
                    .addComponent(jButton2))
                .addGap(7, 7, 7)
                .addGroup(jPanelOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton3)
                    .addComponent(jLabel24, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        jPanel_CardLayout.add(jPanelOptions, "card5");

        getContentPane().add(jPanel_CardLayout, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 610, -1));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_cancelActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton_cancelActionPerformed
    {//GEN-HEADEREND:event_jButton_cancelActionPerformed

        // TODO add your handling code here:
        FATHER_WINDOW_HANDLE.setVisible(true);
        FATHER_WINDOW_HANDLE.setEnabled(true);
        this.dispose();
    }//GEN-LAST:event_jButton_cancelActionPerformed

    private void jButton_nextActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton_nextActionPerformed
    {//GEN-HEADEREND:event_jButton_nextActionPerformed
        switch (screen)
        {
            //If we're on the first screen.. then move to the second screen.
            case 1:
            {
                //Enable back button, cause we can go backto the first screen now.
                jButton_back.setEnabled(true);

                //Remove the previous screen and add the second screen
                jPanel_CardLayout.removeAll();
                jPanel_CardLayout.add(jPanel_choosefile, "2");

                //Make second screen ready
                jPanel_choosefile.setVisible(true);
                jTextField_ConceptLib.setText("");

                //Keep track of what screen we're on.
                screen = 2;

                //Draw the new Screen
                jPanel_CardLayout.repaint();
                jLabel21.setVisible(false);
                jLabel21.setIcon(jLabel16.getIcon());
                break;
            }
            //If we're on the second screen... move to the third screen
            case 2:
            {
                //Make sure user successfully completed step 2 before moving on.
                if (!step2check())
                {
                    break;
                }
                //Remove last panel
                jPanel_CardLayout.removeAll();

                //Put new panel on
                jPanel_CardLayout.add(jPanel_Done, "3");
                jPanel_Done.setVisible(true);

                //Set up new panel
                jLabel7.setText("");
                jLabel8.setText("");
                jLabel9.setText("");
                jLabel10.setVisible(false);
                jLabel11.setVisible(false);
                jLabel12.setVisible(false);
                jLabel16.setVisible(false);

                //Move screen to next one
                screen = 3;

                //repaint
                jPanel_CardLayout.repaint();

                //Evaluate the change
                evaluateChange();

                //repaint
                jPanel_CardLayout.repaint();

                //Break out of ths.
                break;
            }
            //if we're on the third screen move to the fourth
            case 3:
            {
                //Remove last card layout
                jPanel_CardLayout.removeAll();

                //Move to next card
                jPanel_CardLayout.add(jPanelOptions, "4");
                jPanelOptions.setVisible(true);

                //Get screen ready.
                jLabel22.setVisible(true);
                jLabel23.setVisible(true);

                //Move to next screen
                screen = 4;
                jButton_next.setText("Complete");
                jPanel_CardLayout.repaint();
                break;
            }
            //If we're on the last screen then just destroy this gui.
            case 4: //this.setVisible(false);
            {
                FATHER_WINDOW_HANDLE.setVisible(true);
                FATHER_WINDOW_HANDLE.setEnabled(true);
                if(editing)
                    removeOldDict();
                createANewDict();

                config.project.ProjectConf projectconf = new config.project.ProjectConf(
                            env.Parameters.WorkSpace.CurrentProject);
                projectconf.saveConfigure();
                this.dispose();
                break;
            }
        }
    }//GEN-LAST:event_jButton_nextActionPerformed
    
    /**
     * Check the validity of the file that the user added.
     */
    private void evaluateChange()
    {
        //Get the text that the user entered
        conceptLib = jTextField_ConceptLib.getText().trim();

        //Make sure the text is not null or has a length less then one.
        if ((conceptLib == null) || (conceptLib.length() < 1))
        {
            //Set variables, so that the user knows they have to go back
            jLabel7.setText("This is not a valid file name - [" + conceptLib + "]");
            jButton_next.setEnabled(false);
            jLabel10.setIcon(jLabel16.getIcon());
            jLabel10.setVisible(true);
            jLabel16.setText("Please go back to previous step to modify your input");
            jLabel16.setVisible(true);
            Toolkit.getDefaultToolkit().beep();
            return;
        }
        //Check for existence of file
        boolean fexist = commons.Filesys.checkFilesExists(conceptLib);
        if (!fexist)
        {
            //Set variables so the user knows they have to go back
            jLabel7.setText("This file do not exist! - [" + conceptLib + "]");
            jButton_next.setEnabled(false);
            jLabel10.setIcon(jLabel16.getIcon());
            jLabel10.setVisible(true);
            jLabel16.setText("Please go back to previous step to modify your input");
            jLabel16.setVisible(true);
            Toolkit.getDefaultToolkit().beep();
            return;
        }

        //At this point we know it is valid
        jLabel7.setText("File validity checked. - " + conceptLib);
        jLabel10.setIcon(jLabel12.getIcon());
        jLabel10.setVisible(true);

        //count words
        lines = commons.Filesys.countWordsInFile(new File(conceptLib));

        //if there aren't any lines then notify user.
        if (lines < 1)
        {
            //Set variables so the user knows that they have to go back.
            jLabel8.setText("No valid entries found");
            jButton_next.setEnabled(false);
            jLabel11.setIcon(jLabel16.getIcon());
            jLabel11.setVisible(true);
            jLabel16.setText("Please go back to previous step to modify your input");
            jLabel16.setVisible(true);
            Toolkit.getDefaultToolkit().beep();
            return;
        }
        //Set variables so user knows it's a valid dictionary.
        jLabel8.setText(String.valueOf(lines) + " valid concept terms found");
        jLabel11.setIcon(jLabel12.getIcon());
        jLabel11.setVisible(true);
        jLabel9.setText("Change saved!");
        jLabel12.setVisible(true);
        
    }
    private void removeOldDict()
    {
        env.Parameters.VERIFIER_DICTIONARIES.remove(editIndex);
    }
    private void createANewDict()
    {

        Dictionaries.VerifierDictionaryFormat toAdd = new Dictionaries.VerifierDictionaryFormat(conceptLib, jCheckBox1.isSelected(), jComboBox1.getSelectedIndex(), jComboBox2.getSelectedIndex(), charByChar.getSelectedIndex(), checkInside.isSelected(), this.checkFirst.isSelected(), this.checkLast.isSelected(),this.jComboBox3.getSelectedIndex(),jTextField1.getText(), lines);
        if(editing)
            env.Parameters.VERIFIER_DICTIONARIES.add(editIndex, toAdd);
        else
            env.Parameters.VERIFIER_DICTIONARIES.add(toAdd);

        config.project.ProjectConf projectconf = new config.project.ProjectConf(
                    env.Parameters.WorkSpace.CurrentProject);
        projectconf.saveConfigure();
    }
    private boolean step2check()
    {
        conceptLib = jTextField_ConceptLib.getText().trim();
        //System.out.println("----------------" + conceptLib + "=======" + separator );
        if ((conceptLib == null) || (conceptLib.length() < 1))
        {
            jLabel21.setText("Note: You must choose a file before you go to next step!!!");
            jLabel21.setVisible(true);
            Toolkit.getDefaultToolkit().beep();
            return false;
        }
        return true;
    }
    /**
     * Called when back button is pressed.
     * @param evt
     */
    private void jButton_backActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton_backActionPerformed
    {//GEN-HEADEREND:event_jButton_backActionPerformed
        //Based on what screen we're on... go back to previous screen.
        switch (screen)
        {
            //If we're on the second screen go back to the first screen.
            case 2:
                jButton_back.setEnabled(false);                
                jPanel_CardLayout.removeAll();
                jPanel_CardLayout.add(jPanel_Introduction, "1");
                jButton_cancel.setEnabled(true);
                screen = 1;
                jPanel_CardLayout.repaint();
                break;
            //If we're on the third screen go back to the second screen.
            case 3:
                jButton_back.setEnabled(true);                
                jPanel_CardLayout.removeAll();
                jPanel_CardLayout.add(jPanel_choosefile, "2");
                screen = 2;
                jLabel21.setVisible(false);
                jButton_next.setEnabled(true);
                jButton_next.setText("Next");
                jButton_cancel.setEnabled(true);
                jPanel_CardLayout.repaint();
                break;
            //If we're on the fourth screen go back to the third screen.
            case 4:
                jPanel_CardLayout.removeAll();
                jPanel_CardLayout.add(jPanel_Done, "3");
                jPanel_Done.setVisible(true);
                jLabel22.setVisible(false);
                jLabel23.setVisible(false);
                screen = 3;
                jPanel_CardLayout.repaint();
                jPanel_CardLayout.repaint();
                break;

        }
}//GEN-LAST:event_jButton_backActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed
    {//GEN-HEADEREND:event_jButton1ActionPerformed
        // TODO add your handling code here:
        int re = jFileChooser1.showDialog(this, "Set");
        //jLabel8.setText(String.valueOf(re));
        if (re == 0)
        {
            //jFileChooser1.setFileSelectionMode(1);
            String filename = jFileChooser1.getSelectedFile().toString();
            jTextField_ConceptLib.setText(filename);
        }
}//GEN-LAST:event_jButton1ActionPerformed
    @SuppressWarnings("static-access")
    private void formWindowClosed(java.awt.event.WindowEvent evt)//GEN-FIRST:event_formWindowClosed
    {//GEN-HEADEREND:event_formWindowClosed
        // TODO add your handling code here:
        FATHER_WINDOW_HANDLE.setVisible(true);
        FATHER_WINDOW_HANDLE.setEnabled(true);
        UserInterface.Setting f = (UserInterface.Setting) FATHER_WINDOW_HANDLE;
        f.Show_verified_dictionaries_on_list();
    }//GEN-LAST:event_formWindowClosed

    private void formWindowClosing(java.awt.event.WindowEvent evt)//GEN-FIRST:event_formWindowClosing
    {//GEN-HEADEREND:event_formWindowClosing
        FATHER_WINDOW_HANDLE.setVisible(true);
        FATHER_WINDOW_HANDLE.setEnabled(true);
    }//GEN-LAST:event_formWindowClosing

    /**
     * Allow user to get explanation file.
     * @param evt
     */
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton2ActionPerformed
    {//GEN-HEADEREND:event_jButton2ActionPerformed
        int re = jFileChooser1.showDialog(this, "Set");
        //jLabel8.setText(String.valueOf(re));
        if (re == 0)
        {
            //jFileChooser1.setFileSelectionMode(1);
            String filename = jFileChooser1.getSelectedFile().toString();
            jTextField1.setText(filename);
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    /**
     * Check validity of file
     * @param evt
     */
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton3ActionPerformed
    {//GEN-HEADEREND:event_jButton3ActionPerformed
        String fileName = jTextField1.getText();
        if(new File(fileName).isFile())
            jLabel24.setText("Valid File!");
        else
            jLabel24.setText("Invalid File!");
    }//GEN-LAST:event_jButton3ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox charByChar;
    private javax.swing.JCheckBox checkFirst;
    private javax.swing.JCheckBox checkInside;
    private javax.swing.JCheckBox checkLast;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton_back;
    private javax.swing.JButton jButton_cancel;
    private javax.swing.JButton jButton_next;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JFileChooser jFileChooser1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanelOptions;
    private javax.swing.JPanel jPanel_CardLayout;
    private javax.swing.JPanel jPanel_Done;
    private javax.swing.JPanel jPanel_Introduction;
    private javax.swing.JPanel jPanel_choosefile;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField_ConceptLib;
    // End of variables declaration//GEN-END:variables
}
